package com.yulintu.utils;

import com.yulintu.mq.FileSender;
import net.contentobjects.jnotify.JNotifyListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * @author caomin
 * @date 2017/10/25
 * @说明 文件监听
 */
@Component
public class Filejnotify implements JNotifyListener {
    @Autowired
    FileSender sender;


    @Override
    public void fileCreated(int wd, String rootPath, String name) {
        System.out.println("监听到创建文件的动作");
        File file = new File(rootPath +File.separator+ name);
        sender.sendMessage(file);
    }

    @Override
    public void fileDeleted(int wd, String rootPath, String name) {
        System.out.println("fileDeleted");
    }

    @Override
    public void fileModified(int wd, String rootPath, String name) {
        System.out.println("监听到修改文件的动作");
    }

    @Override
    public void fileRenamed(int wd, String rootPath, String oldName, String newName) {
        System.out.println("fileRenamed");
    }
}
